#ifndef __LUOO_SESSION_MANAGER_HPP__
#define __LUOO_SESSION_MANAGER_HPP__

#include <queue>
#include <set>

#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>

#include "luoo_typedef.h"

namespace luoo
{
	template <typename session_type>
	class session_manager : public boost::noncopyable
	{
	public:
		typedef boost::shared_ptr<session_type> session_sptr;

	private:
		typedef std::set<session_sptr> session_set;

	public:
		session_manager()
		{}

		void join(session_sptr new_session)
		{
			boost::mutex::scoped_lock lock(mutex_);

			session_set_.insert(new_session);
		}

		void leave(session_sptr session)
		{
			boost::mutex::scoped_lock lock(mutex_);

			session_set_.erase(session);
		}

		void close_all_session()
		{
			boost::mutex::scoped_lock lock(mutex_);

			for (typename session_set::iterator it = session_set_.begin(); it != session_set_.end(); ++it)
			{
				(*it)->shutdown();
			}

			session_set_.clear();
		}

		std::size_t get_session_cnt() const
		{
			boost::mutex::scoped_lock lock(mutex_);

			return session_set_.size();
		}

	private:
		boost::mutex mutex_;
		session_set session_set_;
	};
}//namespace luoo

#endif//__LUOO_SESSION_MANAGER_HPP__